package com.ysd.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ysd.dao.impl.UserDaoImpl;
import com.ysd.entity.User;
import com.ysd.util.Dateutil;
import com.ysd.util.Result;
/**
 * 
 * 这是一个信息servlet类
 *
 */
public class MessageServlet extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
         String username=request.getParameter("username");//获得前台传来的参数
         String phone =request.getParameter("phone");
         String email =request.getParameter("email");
         String content =request.getParameter("content");
         Date time=new Date();
         String n1=Dateutil.getToString(time);
  
         User user=new User( username, phone, email, content, n1);
         System.out.println(n1);
         response.setCharacterEncoding("UTF-8");//解决乱码,一定要放到 printwriter之前
         PrintWriter out =response.getWriter();//out.print之前.
         UserDaoImpl uDao=new UserDaoImpl();//创建对象
	     int n=uDao.addMessage(user);//通过打点获得对象
		 if(n>0) {
			 out.print(Result.toClient(true, "留言成功",""));
		 }else {
			 out.print(Result.toClient(false, "留言失败","服务器异常"));
		 }
		 out.flush();
		 out.close();
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doGet(request, response);
	}

}